package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.AlarmLog;
import com.ruoyi.system.service.IAlarmLogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: zhoupeng
 * @date: 2021/9/12 16:49
 * @descreption: 报警日志控制层
 */
@Controller
@RequestMapping("/alarm")
public class AlarmLogController extends BaseController {

    @Resource
    private IAlarmLogService alarmLogService;

    @RequiresPermissions("alarm:view")
    @GetMapping()
    public String user() {
        return "system/log/alarm";
    }

    /**
     * 查询数据
     */
    @RequiresPermissions("alarm:log:list")
    @PostMapping("list")
    @ResponseBody
    public TableDataInfo list(AlarmLog alarmLog) {
        startPage();
        List<AlarmLog> list = alarmLogService.selectAlarmLogList(alarmLog);
        return getDataTable(list);
    }

    /**
     * 查询详情
     */
    @RequiresPermissions("alarm:log:detailList")
    @GetMapping("detailList/{id}")
    public String detailList(@PathVariable("id") Long id, ModelMap mmap) {
        AlarmLog alarmLog = new AlarmLog();
        alarmLog.setId(id);
        alarmLog = alarmLogService.selectAlarmLogList(alarmLog).get(0);
        mmap.put("alarmLog", alarmLog);
        return "system/log/alarmDetail";
    }

    @Log(title = "报警日志管理", businessType = BusinessType.EXPORT)
    @RequiresPermissions("alarm:log:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AlarmLog alarmLog) {
        List<AlarmLog> list = alarmLogService.selectAlarmLogList(alarmLog);
        ExcelUtil<AlarmLog> util = new ExcelUtil<>(AlarmLog.class);
        return util.exportExcel(list, "报警日志数据");
    }
}
